import { defineStore } from 'pinia';

export const useExampleStore = defineStore('example', {
    state: () => ({
        scopeData: null,
        school: "",  // 确保初始值是字符串而不是 null/undefined
        userid: ""
    }),
    actions: {
        updateScopeData(data) {
            this.scopeData = data;
        },
        setSchool(school) {
            this.school = school; // 确保传入的是基本类型
        },
        setUserid(userid) {
            this.userid = userid;
        }
    },
    getters: {
        getSchool() {
            return this.school;
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'example-store',
                storage: localStorage,
                paths: ['school', 'userid','scopeData'] // 明确指定要持久化的字段
            }
        ]
    }
});